{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "170bb298",
   "metadata": {},
   "source": [
    "---------\n",
    "* 日期：2022-11-2 | week11 \n",
    "* 课程：Python\n",
    "* 记录人：杨静雯~\n",
    "---------\n",
    "\n",
    "# 本周学习目标\n",
    "\n",
    "> 1.元组\n",
    ">\n",
    "> 2.集合\n",
    ">\n",
    "> 3.字典"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bae1a871",
   "metadata": {},
   "source": [
    "## 1.元组（tuple）\n",
    "\n",
    "> 1.元组的概念和基本形态\n",
    ">\n",
    "> 2.元组的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6dfa99e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1800001, 1800002, 1800003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "user_info = 1800001,1800002,1800003\n",
    "print(user_info,type(user_info))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "27b0c8c9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1800001, 1800002, 1800003] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "user_info_list = [1800001,1800002,1800003]\n",
    "print(user_info_list,type(user_info_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "394e5892",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 取值\n",
    "print(user_info [0])\n",
    "# 切片\n",
    "print(user_info [:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d707120f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e708b85f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=11, tm_mday=2, tm_hour=19, tm_min=11, tm_sec=52, tm_wday=2, tm_yday=306, tm_isdst=0)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "03ad90d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on struct_time object:\n",
      "\n",
      "class struct_time(builtins.tuple)\n",
      " |  struct_time(iterable=(), /)\n",
      " |  \n",
      " |  The time value as returned by gmtime(), localtime(), and strptime(), and\n",
      " |  accepted by asctime(), mktime() and strftime().  May be considered as a\n",
      " |  sequence of 9 integers.\n",
      " |  \n",
      " |  Note that several fields' values are not the same as those defined by\n",
      " |  the C language standard for struct tm.  For example, the value of the\n",
      " |  field tm_year is the actual year, not year - 1900.  See individual\n",
      " |  fields' descriptions for details.\n",
      " |  \n",
      " |  Method resolution order:\n",
      " |      struct_time\n",
      " |      builtins.tuple\n",
      " |      builtins.object\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __reduce__(...)\n",
      " |      Helper for pickle.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  tm_gmtoff\n",
      " |      offset from UTC in seconds\n",
      " |  \n",
      " |  tm_hour\n",
      " |      hours, range [0, 23]\n",
      " |  \n",
      " |  tm_isdst\n",
      " |      1 if summer time is in effect, 0 if not, and -1 if unknown\n",
      " |  \n",
      " |  tm_mday\n",
      " |      day of month, range [1, 31]\n",
      " |  \n",
      " |  tm_min\n",
      " |      minutes, range [0, 59]\n",
      " |  \n",
      " |  tm_mon\n",
      " |      month of year, range [1, 12]\n",
      " |  \n",
      " |  tm_sec\n",
      " |      seconds, range [0, 61])\n",
      " |  \n",
      " |  tm_wday\n",
      " |      day of week, range [0, 6], Monday is 0\n",
      " |  \n",
      " |  tm_yday\n",
      " |      day of year, range [1, 366]\n",
      " |  \n",
      " |  tm_year\n",
      " |      year, for example, 1993\n",
      " |  \n",
      " |  tm_zone\n",
      " |      abbreviation of timezone name\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  n_fields = 11\n",
      " |  \n",
      " |  n_sequence_fields = 9\n",
      " |  \n",
      " |  n_unnamed_fields = 0\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Methods inherited from builtins.tuple:\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(self, key, /)\n",
      " |      Return self[key].\n",
      " |  \n",
      " |  __getnewargs__(self, /)\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __hash__(self, /)\n",
      " |      Return hash(self).\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  count(self, value, /)\n",
      " |      Return number of occurrences of value.\n",
      " |  \n",
      " |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      " |      Return first index of value.\n",
      " |      \n",
      " |      Raises ValueError if the value is not present.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Class methods inherited from builtins.tuple:\n",
      " |  \n",
      " |  __class_getitem__(...) from builtins.type\n",
      " |      See PEP 585\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "a2c8702b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1667387618.7519605"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.time() # 时间戳，可以记录互联网当中所有 数据信息产生、销毁、创建等一系列行为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a5465a6e",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'tuple' object has no attribute 'pop'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Input \u001b[1;32mIn [15]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43muser_info\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpop\u001b[49m(\u001b[38;5;241m1800004\u001b[39m)\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'pop'"
     ]
    }
   ],
   "source": [
    "user_info.pop(1800004) # 一旦创建元组，则无法改变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "0e3168cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.count(180000001)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67660cc1",
   "metadata": {},
   "source": [
    " ## 2. 集合\n",
    " \n",
    " > 1.集合的概念和性质\n",
    " >> 1. 集合的唯一性\n",
    " >> 2. 集合的无序性\n",
    " > 2.集合的方法\n",
    " >> 1. 交集：逻辑运算符—— setA & setB ，setA.intersection(B) => 应用：推荐系统\n",
    " >> 2. 并集：逻辑运算符—— setA | setB ,setA.union(B）=> 应用：快速统计两个集合元素的个数\n",
    " >"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "8274c6fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'apple', 'banana', 'pear', 'orange'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n",
    "print(basket,type(basket))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "7aa7762e",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'set' object is not subscriptable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [18]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mbasket\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'set' object is not subscriptable"
     ]
    }
   ],
   "source": [
    "basket[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "3dee85f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社_user_id = {18000001,18000006,18000007}\n",
    "合唱团_user_id = {1801,1807,18000001,1800009,18000006}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7ddd9df3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{18000001, 18000006}"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id & 合唱团_user_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "074cbb98",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{18000001, 18000006}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.intersection(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "db68555c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id) + len(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "3a43f82c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1801, 1807, 1800009, 18000001, 18000006, 18000007}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id | 合唱团_user_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "77fbb426",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1801, 1807, 1800009, 18000001, 18000006, 18000007}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.union(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "490ba8c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：如果是列表的话，找出重复的项？ =》 从中体现集合的价值\n",
    "\n",
    "舞蹈社_user_id_list = [18000001,18000006,18000007]\n",
    "合唱团_user_id_list = [1801,1807,18000001,1800009,18000006]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2032fcc7",
   "metadata": {},
   "source": [
    "## 3. 字典（dictionaries）\n",
    "> 1. 字典的概念和性质\n",
    ">> 1.性质\n",
    ">>> 1. 无序性\n",
    ">>> 2. key 是唯一的（没有重复的）\n",
    ">>> 3. key 是不可变的\n",
    "\n",
    "> 2. 字典的创建\n",
    ">> 1. 按照字典的形态创建字典\n",
    "```\n",
    "网新1班 = {\n",
    "    180001:\"刘石珍\",\n",
    "    180002:\"黄晰月\",\n",
    "    180003:\"汤雅莉\",\n",
    "    180004:\"郑斐匀\"\n",
    "}\n",
    ">> 2. 使用dict()方法创建字典\n",
    "网新2班 = dict (\n",
    "    stu1901=\"jack\",\n",
    "    stu1902=\"mary\",\n",
    "    stu1903=\"max\",\n",
    "    stu1904=\"11\"\n",
    ")\n",
    "```\n",
    "\n",
    "> 3. 字典的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "2f692863",
   "metadata": {},
   "outputs": [],
   "source": [
    "wechat = {\n",
    "    \"sdfidaibvi888\":[\"888mob\",\"icaland\",\"pyq\",\"lalalalalalalal\",\"1314\",\"yyds\",\"美美哒\"],\n",
    "    \"aheefhuawfnda999\":[\"liushizhen\",\"pig\",\"china\"]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "20672780",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['888mob', 'icaland', 'pyq', 'lalalalalalalal', '1314', 'yyds', '美美哒']"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wechat[\"sdfidaibvi888\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "e7b7c64f",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新1班 = {\n",
    "    180001:\"刘石珍\",\n",
    "    180002:\"黄晰月\",\n",
    "    180003:\"汤雅莉\",\n",
    "    180004:\"郑斐匀\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "b9699933",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{180001: '刘石珍', 180002: '黄晰月', 180003: '汤雅莉', 180004: '郑斐匀'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新1班,type(网新1班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "2c85462b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'刘石珍'"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新1班[180001]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "27549eea",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新2班 = dict (\n",
    "    stu1901=\"jack\",\n",
    "    stu1902=\"mary\",\n",
    "    stu1903=\"max\",\n",
    "    stu1904=\"11\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c6ebf22",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
